package com.gzx.bi.modular.user.mapper;

import com.gzx.bi.modular.screen.entity.GzxHtCallReceiptBusiness;
import com.gzx.bi.modular.user.entity.GzxUserDebt;
import com.gzx.bi.modular.user.vo.GzxUserDebtVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import vip.xiaonuo.common.mapper.BaseMapperPlus;

import java.util.List;

/**
 * 用户所属团队小组
 */
public interface GzxUserDebtMapper extends BaseMapperPlus<GzxUserDebt, GzxUserDebtVo> {

    //插入数据，存在则更新，不存在则插入
    @Insert({
            "<script>",
            "insert into gzx_user_debt(id,belong_project,belong_team,account,name,org_id,position_id,position_level,director_id,tenant_id) " +
                    "values " +
                    " <foreach collection='list' item='item' separator=','>" +
                    " (#{item.id},#{item.belongProject},#{item.belongTeam},#{item.account},#{item.name},#{item.orgId},#{item.positionId},#{item.positionLevel},#{item.directorId},#{item.tenantId}) " +
                    " </foreach> " +
                    " on duplicate key update belong_project = values(belong_project),belong_team = values(belong_team),org_id = values(org_id) ,position_id = values(position_id),director_id = values(director_id) " +
                    "</script>"
    })
    void insertUpdateBatch(List<GzxUserDebt> userList);

    //获取用户的所属项目，小组
    @Select("<script>" +
            "select belong_project belongProject , belong_team belongTeam ,account,director_id directorId from gzx_user_debt " +
            " where account in " +
            "<foreach collection='list' item='item' open='(' separator=',' close=')'>" +
            "   #{item.agentNum}" +
            "</foreach>" +
            "</script>")
    List<GzxUserDebtVo> getUserDebt(List<GzxHtCallReceiptBusiness> list);

}
